package com.feng.app.spider;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;

public class PostWay {

	/**不适用post 使用get方法
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		new Post().start();

	}

}

class Post extends Thread{
	HttpClient client=HttpClients.createDefault();
	
	public void run(){
		
		String path="http://www.lietu.com/";
		
		//直接填入地址即可
		HttpPost post=new HttpPost(path);
		
		List<NameValuePair> para=new ArrayList<>();
		
//		para.add(new BasicNameValuePair("key","e7d26aa3883794cc00a7e51b09e67323"));
//		para.add(new BasicNameValuePair("info","济南天气"));
//		para.add(new BasicNameValuePair("userid","123456"));
		
//		getMethod 在client4中该为了HttpGet
		
//		GetMethod gm=new GetMethod();
		
		try {
			post.setEntity(new UrlEncodedFormEntity(para,"UTF-8"));
			
			
			
			HttpResponse res=client.execute(post);
			
			HttpEntity en=res.getEntity();
			
			InputStream  is=en.getContent();
			
			InputStreamReader isr=new InputStreamReader(is);
			
			BufferedReader br=new BufferedReader(isr);
			
			String line=br.readLine();
			
			String info[]=line.split("\"");
			
			System.out.println(line);
			
			for(String t:info){
				System.out.println(t);
			}
			
			
			
			
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	
	
}
